home *** CD-ROM | disk | FTP | other *** search
/ PCMania 75 / PCMania CD75_1.iso / lycos / netscape / netcast.z / ncjs10.jar / utils.js < prev    next >
Text File  |  1997-12-16  |  5KB  |  250 lines

  1. /*
  2.  * utils.js
  3.  * 
  4.  * Copyright (c) 1997 Netscape Communications Corporation, All Rights Reserved
  5.  * 
  6.  * Utility functions for the Netcaster
  7.  */
  8.  
  9. function jsdebug_break()
  10. {
  11.     var x;
  12.     x = 1;
  13. }
  14.  
  15. var debug = false;
  16. var platform = 0;
  17. var defaultContainer = null;
  18.  
  19. function ChannelObject()
  20. {
  21.     this.name = "";
  22.     this.url = "";
  23.     this.desc = "";
  24.  
  25.     this.intervalTime = 7200;
  26.     this.absoluteTime = 0;
  27.     
  28.     this.estCacheSize = -1;
  29.     this.maxCacheSize = 5000000;
  30.  
  31.     this.topHint = 0;
  32.     this.leftHint = 0;
  33.     this.widthHint =  screen.availWidth * 2 / 3;
  34.     this.heightHint = screen.availHeight * 3 / 4;
  35.  
  36.     this.mode="window";
  37.  
  38.     this.type="1";
  39.     this.depth="2";
  40.     this.crawlExtLinks = true;
  41. }
  42.  
  43. function batchNetscapePrefs(keys, values, warn, set)
  44. {
  45.     var pref;
  46.     var setPrefs = false;
  47.  
  48.     if (arguments.length == 4) {
  49.         setPrefs=set;
  50.     }
  51.  
  52.     if (setPrefs) {
  53.         netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite"); 
  54.     } else {
  55.         netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead"); 
  56.     }
  57.  
  58.     for (var i=0; i < keys.length; i++) {
  59.         if (setPrefs) {
  60.             var str = 'navigator.preference("' + keys[i] + '", "' + values[i] + '");'
  61.             eval(str);
  62.         } else {
  63.             pref = navigator.preference(keys[i]);
  64.  
  65.             if ((!pref) || (pref == null)) 
  66.             {
  67.                 if (warn)
  68.                     alert(getLocalString("The preference ") + keys[i] + getLocalString(" is missing from your preferences file and a default value has been used.  Please contact your administrator."));
  69.             } else {
  70.                 values[i] = pref;
  71.             }
  72.         }
  73.     }
  74.  
  75.     if (setPrefs) {
  76.         navigator.savePreferences();
  77.     }
  78.  
  79.     return;
  80. }
  81.  
  82. function GetNetscapePref(prefKey, defaultValue, warn)
  83. {
  84.     var pref;
  85.  
  86.     netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead"); 
  87.  
  88.     pref = navigator.preference(prefKey);
  89.  
  90.     if ((!pref) || (pref == null)) 
  91.     {
  92.         if (warn)
  93.             alert(getLocalString("The preference ") + prefKey + getLocalString(" is missing from your preferences file and a default value has been used.  Please contact your administrator."));
  94.  
  95.         pref = defaultValue;
  96.     }
  97.  
  98.     return pref;
  99. }
  100.  
  101. function GetNetscapePrefBool(prefKey, defaultValue, warn)
  102. {
  103.     var pref;
  104.  
  105.     netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead"); 
  106.  
  107.     pref = navigator.preference(prefKey);
  108.  
  109.     if (!pref) {
  110.         return false;
  111.     } else {
  112.         if (pref == null) {
  113.             if (warn)
  114.                 alert(getLocalString("The preference ") + prefKey + getLocalString(" is missing from your preferences file and a default value has been used.  Please contact your administrator."));
  115.  
  116.             pref = defaultValue;
  117.         } else {
  118.             pref = true;
  119.         }
  120.     }    
  121.     
  122.     return pref;
  123. }
  124.  
  125. function SetNetscapePref(prefKey, value)
  126. {
  127.     netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite"); 
  128.  
  129.     var str = 'navigator.preference("' + prefKey + '", "' + value + '");'
  130.     eval(str);
  131. }
  132.  
  133. function SetNetscapePrefBool(prefKey, value)
  134. {
  135.     netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite"); 
  136.  
  137.     var str = 'navigator.preference("' + prefKey + '", ' + value + ');'
  138.     eval(str);
  139. }
  140.  
  141. function SecureMoveWindow(theWindow, x, y)
  142. {
  143.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  144.  
  145.     theWindow.moveTo(x, y);
  146. }
  147.  
  148. function SecureWindowOpen(theWindow, str1, str2, str3)
  149. {
  150.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  151.  
  152.     new_window = theWindow.window.open(str1, str2, str3) ;
  153.     
  154.     return new_window ;
  155. }
  156.  
  157. function SupressDblClick(e)
  158. {
  159.     return false;
  160. }
  161.  
  162. function SupressRightMouse(e)
  163. {
  164.     if (e.which > 1)
  165.         return false;
  166.  
  167.     return routeEvent(e);
  168. }
  169.  
  170. function SupressDrag(e)
  171. {
  172.     if (e.type = "dragdrop")
  173.         return false;
  174. }
  175.  
  176. function SupressError(errMsg) 
  177. {
  178.     if (typeof(errMsg) != "string") {
  179.         java.lang.System.out.println("JS Error: Error loading image");
  180.         return false;
  181.     }
  182.  
  183.     if (errMsg.indexOf('netscape/security/ForbiddenTargetException') != -1) {
  184.         alert("Para abrir Netcaster son necesarios determinados privilegios. " +
  185.               "Para usar Netscape Netcaster, debe conceder autorizaci≤n a los programas de b·squeda en la red. " +
  186.               "Para conceder la autorizaci≤n y evitar este mensaje en el futuro, marque la casilla \"Mantener esta decisi≤n\" " +
  187.               "antes de hacer clic en Autorizar.");
  188.         components["netcaster"].forceCloseNetcaster();
  189.         return true;
  190.     }
  191.  
  192.  
  193.     java.lang.System.out.println("JS Error: " + errMsg);
  194.  
  195.     return true; 
  196. }
  197.  
  198. function setDebugBool() 
  199. {
  200.     debug = false;
  201. }
  202.  
  203. function setPlatform() 
  204. {
  205.     var plat = navigator.platform;
  206.  
  207.     if (plat.indexOf("Win") != -1)
  208.         platform = 1;
  209.     else if(plat.indexOf("Mac") != -1)
  210.         platform = 2;
  211.     else
  212.         platform = 3;
  213. }
  214.  
  215. function isWindows() {
  216.     return (platform==1) ? true : false;
  217. }
  218.  
  219. function isMac() {
  220.     return (platform==2) ? true : false;
  221. }
  222.  
  223. function isUnix() {
  224.     return (platform==3) ? true : false;
  225. }
  226.  
  227. function getLocalString(keyString)
  228. {
  229.     if ((typeof depth == "undefined") || (depth.titlebar.document.demo == null)) {
  230.         return keyString;
  231.     }
  232.  
  233.     return depth.titlebar.document.demo.getLocalString(keyString);
  234. }
  235.  
  236.  
  237. function getDefaultContainer() {
  238.     if (defaultContainer == null) {
  239.         defaultContainer = GetNetscapePref("netcaster.defaultContainer", "channel", false);
  240.     }
  241.  
  242.     return defaultContainer;
  243. }
  244.  
  245.  
  246. setDebugBool();
  247. setPlatform();
  248.  
  249. void(0);
  250.